package com.dkm.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.dkm.entity.Message;

public interface MessageRepository extends JpaRepository<Message, Integer> {

	/**
	 * 根据发送人和接收人获取最新的10条消息
	 * @param sender_id
	 * @param receiver_id
	 * @return
	 */
	@Query(value = "select * from(select * from message where " + 
			"sender_id=:sender_id and receiver_id=:receiver_id or " + 
			"sender_id=:receiver_id and receiver_id=:sender_id " + 
			"order by send_time desc limit 10) a order by a.send_time asc",nativeQuery = true)
	List<Message> getMessagesBySender_idAndReceiver_id(@Param("sender_id")String sender_id,@Param("receiver_id")String receiver_id);
}
